﻿using System;
using System.Collections.Generic;

namespace GeoAPI.Geometries
{
	public static class OrdinatesUtility
	{
		public static int OrdinatesToDimension(Ordinates ordinates)
		{
			int num = 2;
			if ((ordinates & Ordinates.Z) != Ordinates.None)
			{
				num++;
			}
			if ((ordinates & Ordinates.M) != Ordinates.None)
			{
				num++;
			}
			return num;
		}

		public static Ordinates DimensionToOrdinates(int dimension)
		{
			if (dimension == 3)
			{
				return Ordinates.XYZ;
			}
			if (dimension == 4)
			{
				return Ordinates.XYZM;
			}
			return Ordinates.XY;
		}

		public static Ordinate[] ToOrdinateArray(Ordinates ordinates, int maxEval = 4)
		{
			if (maxEval > 32)
			{
				maxEval = 32;
			}
			List<Ordinate> list = new List<Ordinate>(maxEval);
			for (int i = 0; i < maxEval; i++)
			{
				if ((ordinates & (Ordinates)(1 << i)) != Ordinates.None)
				{
					list.Add((Ordinate)i);
				}
			}
			return list.ToArray();
		}

		public static Ordinates ToOrdinatesFlag(params Ordinate[] ordinates)
		{
			Ordinates ordinates2 = Ordinates.None;
			foreach (Ordinate ordinate in ordinates)
			{
				ordinates2 |= (Ordinates)(1 << (int)ordinate);
			}
			return ordinates2;
		}
	}
}
